package com.example.plotactivity;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.Arrays;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;

import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYStepMode;

public class MainActivity extends Activity {
	
    private XYPlot xyPlot;
    
    final String[] mMonths = new String[] {
        "Jan","Feb", "Mar","Apr", "May","Jun",
        "Jul", "Aug","Sep","Oct", "Nov","Dec"
    };
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // initialize our XYPlot reference:
        xyPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
 
        Number[] income =  {2000, 2500, 2700, 3000, 2800, 3500, 3700, 3800 };
        Number[] expense = {2200, 2700, 2900, 2800, 2600, 3000, 3300, 3400 };
 
        // Converting the above income array into XYSeries
        XYSeries incomeSeries = new SimpleXYSeries(
            Arrays.asList(income),                   // array => list
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY , // Y_VALS_ONLY means use the element index as the x value
            "Income");                                  // Title of this series
 
        // Converting the above expense array into XYSeries
        XYSeries expenseSeries = new SimpleXYSeries(
            Arrays.asList(expense),                 // array => list
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
            "Expense");                                // Title of this series
 
        // Create a formatter to format Line and Point of income series
        LineAndPointFormatter incomeFormat = new LineAndPointFormatter(
            Color.rgb(0, 0, 255),                   // line color
            Color.rgb(200, 200, 200),               // point color
            null );                                    // fill color (none)
 
        // Create a formatter to format Line and Point of expense series
        LineAndPointFormatter expenseFormat = new LineAndPointFormatter(
            Color.rgb(255, 0, 0),                   // line color
            Color.rgb(200, 200, 200),               // point color
            null);                                    // fill color (none)
 
        // add expense series to the xyplot:
        xyPlot.addSeries(expenseSeries,expenseFormat);
 
        // add income series to the xyplot:
        xyPlot.addSeries(incomeSeries, incomeFormat);
 
        // Formatting the Domain Values ( X-Axis )
//        xyPlot.setDomainValueFormat(new Format() {
// 
//            @Override
//            public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
//                return new StringBuffer( mMonths[ ( (Number)obj).intValue() ]  );
//            }
// 
//            @Override
//            public Object parseObject(String source, ParsePosition pos) {
//                return null;
//            }
//        });
 
        xyPlot.setDomainLabel("");
        xyPlot.setRangeLabel("Amount in Dollars");
 
        // Increment X-Axis by 1 value
        xyPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
        
        xyPlot.getGraphWidget().getBackgroundPaint().setColor(Color.BLACK);
        xyPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.BLACK);

        xyPlot.getGraphWidget().setRangeLabelWidth(50);
 
        // Reduce the number of range labels
        xyPlot.setTicksPerRangeLabel(4);
 
        // Reduce the number of domain labels
        xyPlot.setTicksPerDomainLabel(1);
        
        xyPlot.setPlotPadding(-10, 20, -10, -10);
        
        xyPlot.redraw();
    }
   
}
